int* largestValues(struct TreeNode* root, int* returnSize) {
    *returnSize=0;
    if(root==NULL)
        return NULL;
    int *ret;
    int ret_count=0;
    ret=(int *)malloc(sizeof(int)*10001);
    struct TreeNode* queue[10001];
    struct TreeNode* p;
    int front=-1,tail=-1;
    queue[++tail]=root;
    while(front!=tail)
    {
        int current_count=tail-front;
        int current_max=queue[front+1]->val;
        for(int i=0;i<current_count;i++)
        {
            p=queue[++front];
            if(p->val > current_max)
                current_max = p->val;
            if(p->left!=NULL)
                queue[++tail]=p->left;
            if(p->right!=NULL)
                queue[++tail]=p->right;

        }
        ret[ret_count]=current_max;
        ret_count++;
    }
    *returnSize=ret_count;
    return ret;
}